/** @noSelfInFile **/
import {IEffectAdapter} from "../../adapterInterface/model2/IEffectAdapter";
import {LocModel} from "../../../base/LocModel";
import {UnitModel} from "../../../adapterModel/model3/UnitModel";
import {EffectAnimation} from "../../../../../type/Type";


export class EffectAadapter implements IEffectAdapter {

  createHandleOnLoc(path: string, locModel: LocModel): any {
    return AddSpecialEffect(path, locModel.x, locModel.y)
  }

  createHandleOnUnit(path: string, unitHandle: UnitModel, point: string): any {
    return AddSpecialEffectTarget(path, unitHandle.handle, point)
  }

  destroy(handle: any): void {
    handle_unref(handle);
    DestroyEffectBJ(handle);
  }

  setShow(handle: any, bool: boolean, defaultSize: number): void {
    if (bool) {
      this.setSize(handle, defaultSize)
      // EXPlayEffectAnimation(handle, EffectAnimation.stand, '');
    } else {
      this.setSize(handle, 0)
    }
  }

  getShow(handle: any): boolean {
    return this.getSize(handle) > 0
  }

  getLoc(handle: any): LocModel {
    const x = EXGetEffectX(handle);
    const y = EXGetEffectY(handle);
    const z = EXGetEffectZ(handle);
    return new LocModel(x, y, z)
  }

  getSize(handle: any): number {
    return EXGetEffectSize(handle);
  }

  setAngleX(handle: any, value: number): void {
    EXEffectMatRotateX(handle, value)
  }

  setAngleY(handle: any, value: number): void {
    EXEffectMatRotateY(handle, value)
  }

  setAngleZ(handle: any, value: number): void {
    EXEffectMatRotateZ(handle, value)
  }

  setLoc(handle: any, loc: LocModel): void {
    EXSetEffectXY(handle, loc.x, loc.y);
    if (loc.z) {
      EXSetEffectZ(handle, loc.z);
    }
  }

  setSize(handle: any, value: number): void {
    EXSetEffectSize(handle, value);
  }

  bindHandle(handle: any): void {
    handle_ref(handle);
  }
  equal(handle1: any, handle2: any): boolean {
    return (GetHandleId(handle1) === GetHandleId(handle2))
  }

  isValid(handle: any): boolean {
    if (handle) {
      return true;
    }
    return false;
  }
}
